package com.atguigu.eduservice.controller.front;

import com.atguigu.common_uitls.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * zz: wzh
 * time 2022 10 02 20 47
 **/
@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {
    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduTeacherService eduTeacherService;
    //查询前8条热门课程,4名名师
    @GetMapping("index")
    public R index(){
        QueryWrapper<EduCourse> queryWrapper=new QueryWrapper();
        queryWrapper.orderByDesc("id");
        queryWrapper.last("limit 8");
        List<EduCourse> list =
                eduCourseService.list(queryWrapper);
        QueryWrapper<EduTeacher> wrapper=new QueryWrapper();
        queryWrapper.orderByDesc("id");
        queryWrapper.last("limit 4");
        List<EduTeacher> TeacherList =
                eduTeacherService.list(wrapper);
        return R.ok().data("eduList",list).data("teacherList",TeacherList);
    }
}
